package cz.cvut.vrtisja2.muchktom.view.newItem;

import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import cz.cvut.vrtisja2.muchktom.R;
import cz.cvut.vrtisja2.muchktom.view.spinner.ISpinnerDataStrategy;

public class CustomDialogAct {
	//====================Static methods===================
	public static Dialog getCustomDialog(Context ctx, final Spinner spinner, final ISpinnerDataStrategy strategy,int pos){
		final Dialog d = new Dialog(ctx);		
		d.setContentView(R.layout.spinner_add_dialog);
		d.setTitle("hello");
		final int position=pos;
		final EditText editText= (EditText) d.findViewById(R.id.cusomDialogInput);
		final Button okButton=(Button)d.findViewById(R.id.okDialogButton);
		final Button cancelButton=(Button)d.findViewById(R.id.cancelDialogButton);
		
		okButton.setOnClickListener(new OnClickListener() {			
			@Override
			public void onClick(View v) {
			strategy.addToDataSource(position, editText.getText().toString());
			spinner.setSelection(position);			
			d.dismiss();
			}
		});
		
		cancelButton.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				spinner.setSelection(0);
				//TODO: vyresit co se stane po kliknuti na cancel
				d.dismiss();
				
			}
		});
		
		return d;		
	}

	//====================Instance variables==================

	//====================Constructors========================

	//====================Instance Methods====================

	//====================Getters & Setters===================

	//====================Inner classes=======================

}
